package com.ihg.hiex.entity.user;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import com.ihg.hiex.entity.session.before.finaltest.FinalTest;

/**
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "assessor_certificate_record")
public class AssessorCertificateRecord {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** assessor elearning M1 id */
    private Long elearningOneId;
    
    /** assessor elearning M1 score */
    private int elearningOneScore;
    
    private boolean finishElearningOne;
    
    /** assessor elearning M2 id */
    private Long elearningTwoId;
    
    /** assessor elearning M2 score */
    private int elearningTwoScore;
    
    private boolean finishElearningTwo;
    
    /** assessor elearning M3 id */
    private Long elearningThreeId;
    
    /** assessor elearning M3 score */
    private int elearningThreeScore;
    
    private boolean finishElearningThree;
    
    /** assessor final test */
    private Long finalTestId;
    
    /** assessor final test score */
    private int finalTestScore;
    
    private boolean finishFinalTest;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Assessor assessor;
    
    /** 状态 */
    @Enumerated(EnumType.STRING)
    private CertificateRecordStatus status;
    
    /** 创建时间 */
    private Date createTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * 
     */
    public AssessorCertificateRecord() {
    }
    
    /**
     * 
     * @param assessor
     * @param elearningOne
     * @param elearningTwo
     */
    public AssessorCertificateRecord(Assessor assessor, AssessorElearning elearningOne, AssessorElearning elearningTwo,
            AssessorElearning elearningThree) {
        this.elearningOneId = elearningOne.getId();
        this.elearningOneScore = elearningOne.getScore();
        this.finishElearningOne = false;
        this.elearningTwoId = elearningTwo.getId();
        this.elearningTwoScore = elearningTwo.getScore();
        this.finishElearningTwo = false;
        this.elearningThreeId = elearningThree.getId();
        this.elearningThreeScore = elearningThree.getScore();
        this.finishElearningTwo = false;
        this.finalTestScore = 0;
        this.finishFinalTest = false;
        this.assessor = assessor;
        this.status = CertificateRecordStatus.PROCESSING;
        this.createTime = new Date();
        this.disabled = false;
    }
    
    /**
     * 
     * @param assessorElearning
     * @return
     */
    public AssessorCertificateRecord editElearning(AssessorElearning assessorElearning) {
        if(this.elearningOneId == assessorElearning.getId()) {
            this.elearningOneScore = assessorElearning.getScore();
            this.finishElearningOne = StringUtils.equalsIgnoreCase(assessorElearning.getStatus(), "passed") ? true : false;
        } else if(this.elearningTwoId == assessorElearning.getId()) {
            this.elearningTwoScore = assessorElearning.getScore();
            this.finishElearningTwo = StringUtils.equalsIgnoreCase(assessorElearning.getStatus(), "passed") ? true : false;
        } else if(this.elearningThreeId == assessorElearning.getId()) {
            this.elearningThreeScore = assessorElearning.getScore();
            this.finishElearningThree = StringUtils.equalsIgnoreCase(assessorElearning.getStatus(), "passed") ? true : false;
        }
        return this;
    }
    
    /**
     * 
     * @param assessorElearning
     * @return
     */
    public AssessorCertificateRecord finishElearning(AssessorElearning assessorElearning) {
        if(this.elearningOneId == assessorElearning.getId()) {
            this.finishElearningOne = true;
        } else if(this.elearningTwoId == assessorElearning.getId()) {
            this.finishElearningTwo = true;
        } else if(this.elearningThreeId == assessorElearning.getId()) {
            this.finishElearningThree = true;
        }
        return this;
    }
    
    /**
     * 
     * @param finalTest
     * @return
     */
    public AssessorCertificateRecord editFinalTest(FinalTest finalTest) {
        this.finalTestId = finalTest.getId();
        this.finalTestScore = finalTest.getCorrectRateOne().multiply(new BigDecimal("100")).intValue();
        this.finishFinalTest = finalTest.isFinishOne();
        return this;
    }
    
    /**
     * 
     * @param status
     * @return
     */
    public AssessorCertificateRecord changeStatus(CertificateRecordStatus status) {
        this.status = status;
        return this;
    }
    
    /**
     * 
     * @param finalTest
     * @param status
     * @return
     */
    public AssessorCertificateRecord finishFinalTest(FinalTest finalTest, CertificateRecordStatus status) {
        this.finalTestId = finalTest.getId();
        this.finalTestScore = finalTest.getCorrectRateOne().multiply(new BigDecimal("100")).intValue();
        this.finishFinalTest = finalTest.isFinishOne() && finalTest.isFinishTwo();
        this.status = status;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the elearningOneId
     */
    public Long getElearningOneId() {
        return elearningOneId;
    }

    /**
     * @return the elearningOneScore
     */
    public int getElearningOneScore() {
        return elearningOneScore;
    }

    /**
     * @return the finishElearningOne
     */
    public boolean isFinishElearningOne() {
        return finishElearningOne;
    }

    /**
     * @return the elearningTwoId
     */
    public Long getElearningTwoId() {
        return elearningTwoId;
    }

    /**
     * @return the elearningTwoScore
     */
    public int getElearningTwoScore() {
        return elearningTwoScore;
    }

    /**
     * @return the finishElearningTwo
     */
    public boolean isFinishElearningTwo() {
        return finishElearningTwo;
    }

    /**
     * @return the elearningThreeId
     */
    public Long getElearningThreeId() {
        return elearningThreeId;
    }

    /**
     * @return the elearningThreeScore
     */
    public int getElearningThreeScore() {
        return elearningThreeScore;
    }

    /**
     * @return the finishElearningThree
     */
    public boolean isFinishElearningThree() {
        return finishElearningThree;
    }

    /**
     * @return the finalTestId
     */
    public Long getFinalTestId() {
        return finalTestId;
    }

    /**
     * @return the finalTestScore
     */
    public int getFinalTestScore() {
        return finalTestScore;
    }

    /**
     * @return the finishFinalTest
     */
    public boolean isFinishFinalTest() {
        return finishFinalTest;
    }

    /**
     * @return the assessor
     */
    public Assessor getAssessor() {
        return assessor;
    }

    /**
     * @return the status
     */
    public CertificateRecordStatus getStatus() {
        return status;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param elearningOneId the elearningOneId to set
     */
    public void setElearningOneId(Long elearningOneId) {
        this.elearningOneId = elearningOneId;
    }

    /**
     * @param elearningOneScore the elearningOneScore to set
     */
    public void setElearningOneScore(int elearningOneScore) {
        this.elearningOneScore = elearningOneScore;
    }

    /**
     * @param finishElearningOne the finishElearningOne to set
     */
    public void setFinishElearningOne(boolean finishElearningOne) {
        this.finishElearningOne = finishElearningOne;
    }

    /**
     * @param elearningTwoId the elearningTwoId to set
     */
    public void setElearningTwoId(Long elearningTwoId) {
        this.elearningTwoId = elearningTwoId;
    }

    /**
     * @param elearningTwoScore the elearningTwoScore to set
     */
    public void setElearningTwoScore(int elearningTwoScore) {
        this.elearningTwoScore = elearningTwoScore;
    }

    /**
     * @param finishElearningTwo the finishElearningTwo to set
     */
    public void setFinishElearningTwo(boolean finishElearningTwo) {
        this.finishElearningTwo = finishElearningTwo;
    }

    /**
     * @param elearningThreeId the elearningThreeId to set
     */
    public void setElearningThreeId(Long elearningThreeId) {
        this.elearningThreeId = elearningThreeId;
    }

    /**
     * @param elearningThreeScore the elearningThreeScore to set
     */
    public void setElearningThreeScore(int elearningThreeScore) {
        this.elearningThreeScore = elearningThreeScore;
    }

    /**
     * @param finishElearningThree the finishElearningThree to set
     */
    public void setFinishElearningThree(boolean finishElearningThree) {
        this.finishElearningThree = finishElearningThree;
    }

    /**
     * @param finalTestId the finalTestId to set
     */
    public void setFinalTestId(Long finalTestId) {
        this.finalTestId = finalTestId;
    }

    /**
     * @param finalTestScore the finalTestScore to set
     */
    public void setFinalTestScore(int finalTestScore) {
        this.finalTestScore = finalTestScore;
    }

    /**
     * @param finishFinalTest the finishFinalTest to set
     */
    public void setFinishFinalTest(boolean finishFinalTest) {
        this.finishFinalTest = finishFinalTest;
    }

    /**
     * @param assessor the assessor to set
     */
    public void setAssessor(Assessor assessor) {
        this.assessor = assessor;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(CertificateRecordStatus status) {
        this.status = status;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
}
